Skip to content

ASoC: SOF: core: harden shutdown helper - #2791

Merged
kv2019i merged 1 commit into
thesofproject:topic/sof-devfrom
plbossart:fix/shutdown
Mar 22, 2021
Merged

kv2019i merged 1 commit into
thesofproject:topic/sof-devfrom
plbossart:fix/shutdown

Conversation

@plbossart

Copy link
Copy Markdown
Member

When the probe is handled in a workqueue, we must use
cancel_work_sync() in the shutdown helper to avoid possible race
conditions.

Likewise, when a failure occurs in a workqueue, we should not try to
access hardware registers and create more problems

Fixes: daff7f1 ("ASoC: SOF: add snd_sof_device_shutdown() helper for shutdown")
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com

ranj063
ranj063 previously approved these changes Mar 15, 2021
@plbossart

Copy link
Copy Markdown
Member Author

This PR needs more work, when an error occurs during the pm_runtime_resume() done in pci_shutdown(), then the firmware boot may be IN_PROGRESS. The use of state > FW_BOOT_NOT_STARTED is not fully correct, this doesn't cover an error on resume. @ranj063 I'll need your help on this one.

upextreme-reboot-loop.txt

@plbossart

Copy link
Copy Markdown
Member Author

It looks like we have a race condition somewhere. The log below shows a correlation between the failures and actually resuming in pci_device_shutdown. When something triggers an earlier resume, there is no issue.

upextreme-reboot-loop2.txt

working pattern

[   41.200229] systemd-shutdown[1]: Rebooting.
[   41.201592] sof-audio-pci-intel-cnl 0000:00:1f.3: pci_device_shutdown: pm_runtime_resume: start
[   41.202823] sof-audio-pci-intel-cnl 0000:00:1f.3: pci_device_shutdown: pm_runtime_resume: done
[   41.203997] sof-audio-pci-intel-cnl 0000:00:1f.3: pci_device_shutdown: shutdown start
[   41.205184] sof-audio-pci-intel-cnl 0000:00:1f.3: snd_sof_device_shutdown: fw state 5
[   41.206374] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0x20140000 successful
[   41.207601] sof-audio-pci-intel-cnl 0000:00:1f.3: ipc tx: 0x40010000: GLB_PM_MSG: CTX_SAVE
[   41.208857] sof-audio-pci-intel-cnl 0000:00:1f.3: ipc tx succeeded: 0x40010000: GLB_PM_MSG: CTX_SAVE
[   41.210128] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0x1010f0f successful
[   41.211326] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0xf0f successful
[   41.212497] sof-audio-pci-intel-cnl 0000:00:1f.3: DSP core(s) enabled? 0 : core_mask 1
[   41.213761] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIR: 00000010 at  00000044
[   41.214967] sof-audio-pci-intel-cnl 0000:00:1f.3: Turning i915 HDAC power 0
[   41.216231] sof-audio-pci-intel-cnl 0000:00:1f.3: Current DSP power state: D3
[   41.217465] sof-audio-pci-intel-cnl 0000:00:1f.3: pci_device_shutdown: shutdown done
[   41.222661] igb 0000:01:00.0: pci_device_shutdown: pm_runtime_resume: start
[   41.223860] igb 0000:01:00.0: pci_device_shutdown: pm_runtime_resume: done
[   41.225115] igb 0000:01:00.0: pci_device_shutdown: shutdown start

non-working pattern

[   23.239011] systemd-shutdown[1]: Rebooting.
[   23.240568] sof-audio-pci-intel-cnl 0000:00:1f.3: pci_device_shutdown: pm_runtime_resume: start
[   23.254216] sof-audio-pci-intel-cnl 0000:00:1f.3: Turning i915 HDAC power 1
[   23.260089] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIR: 00000000 at  00000044
[   23.264536] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIR: 00000040 at  00000048
[   23.265968] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIW: 00000000 at  00000048
[   23.270287] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIR: 00000000 at  00000048
[   23.271633] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIW: 00000040 at  00000048
[   23.274612] sof-audio-pci-intel-cnl 0000:00:1f.3: Turning i915 HDAC power 0
[   23.275989] sof-audio-pci-intel-cnl 0000:00:1f.3: Current DSP power state: D0I0
[   23.277380] sof-audio-pci-intel-cnl 0000:00:1f.3: loading firmware
[   23.278747] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIR: 00000002 at  00000048
[   23.280129] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIW: 00000000 at  00000048
[   23.281484] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIR: 00000000 at  00000044
[   23.282820] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIW: 00000004 at  00000044
[   23.284161] sof-audio-pci-intel-cnl 0000:00:1f.3: booting DSP firmware
[   23.285571] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0x40000 successful
[   23.286911] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0x40000 successful
[   23.288244] sof-audio-pci-intel-cnl 0000:00:1f.3: period_bytes:0x0
[   23.289620] sof-audio-pci-intel-cnl 0000:00:1f.3: periods:1
[   23.290957] sof-audio-pci-intel-cnl 0000:00:1f.3: Attempting iteration 0 of Core En/ROM load...
[   23.292236] sof-audio-pci-intel-cnl 0000:00:1f.3: DSP core(s) enabled? 0 : core_mask f
[   23.293554] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0xf0f0f0f successful
[   23.294898] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0xf0f0f00 successful
[   23.296197] sof-audio-pci-intel-cnl 0000:00:1f.3: unstall/run core: core_mask = f
[   23.297532] sof-audio-pci-intel-cnl 0000:00:1f.3: DSP core(s) enabled? 1 : core_mask f
[   23.298932] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0xf0f0000 successful
[   23.300238] sof-audio-pci-intel-cnl 0000:00:1f.3: unstall/run core: core_mask = 1
[   23.301572] sof-audio-pci-intel-cnl 0000:00:1f.3: DSP core(s) enabled? 1 : core_mask 1
[   23.803068] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0x0 timedout
[   23.804428] sof-audio-pci-intel-cnl 0000:00:1f.3: unknown ROM status value 05000001
[   23.805823] sof-audio-pci-intel-cnl 0000:00:1f.3: status = 0x00000000 panic = 0x00000000
[   23.807164] sof-audio-pci-intel-cnl 0000:00:1f.3: extended rom status:  0x5000001 0x0 0x0 0x0 0x0 0x0 0x1811102 0x0

Comment thread sound/soc/sof/core.c Resolved
@libinyang

Copy link
Copy Markdown

It looks like we have a race condition somewhere. The log below shows a correlation between the failures and actually resuming in pci_device_shutdown. When something triggers an earlier resume, there is no issue.

upextreme-reboot-loop2.txt

working pattern

[   41.200229] systemd-shutdown[1]: Rebooting.
[   41.201592] sof-audio-pci-intel-cnl 0000:00:1f.3: pci_device_shutdown: pm_runtime_resume: start
[   41.202823] sof-audio-pci-intel-cnl 0000:00:1f.3: pci_device_shutdown: pm_runtime_resume: done
[   41.203997] sof-audio-pci-intel-cnl 0000:00:1f.3: pci_device_shutdown: shutdown start
[   41.205184] sof-audio-pci-intel-cnl 0000:00:1f.3: snd_sof_device_shutdown: fw state 5
[   41.206374] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0x20140000 successful
[   41.207601] sof-audio-pci-intel-cnl 0000:00:1f.3: ipc tx: 0x40010000: GLB_PM_MSG: CTX_SAVE
[   41.208857] sof-audio-pci-intel-cnl 0000:00:1f.3: ipc tx succeeded: 0x40010000: GLB_PM_MSG: CTX_SAVE
[   41.210128] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0x1010f0f successful
[   41.211326] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0xf0f successful
[   41.212497] sof-audio-pci-intel-cnl 0000:00:1f.3: DSP core(s) enabled? 0 : core_mask 1
[   41.213761] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIR: 00000010 at  00000044
[   41.214967] sof-audio-pci-intel-cnl 0000:00:1f.3: Turning i915 HDAC power 0
[   41.216231] sof-audio-pci-intel-cnl 0000:00:1f.3: Current DSP power state: D3
[   41.217465] sof-audio-pci-intel-cnl 0000:00:1f.3: pci_device_shutdown: shutdown done
[   41.222661] igb 0000:01:00.0: pci_device_shutdown: pm_runtime_resume: start
[   41.223860] igb 0000:01:00.0: pci_device_shutdown: pm_runtime_resume: done
[   41.225115] igb 0000:01:00.0: pci_device_shutdown: shutdown start

non-working pattern

[   23.239011] systemd-shutdown[1]: Rebooting.
[   23.240568] sof-audio-pci-intel-cnl 0000:00:1f.3: pci_device_shutdown: pm_runtime_resume: start
[   23.254216] sof-audio-pci-intel-cnl 0000:00:1f.3: Turning i915 HDAC power 1
[   23.260089] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIR: 00000000 at  00000044
[   23.264536] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIR: 00000040 at  00000048
[   23.265968] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIW: 00000000 at  00000048
[   23.270287] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIR: 00000000 at  00000048
[   23.271633] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIW: 00000040 at  00000048
[   23.274612] sof-audio-pci-intel-cnl 0000:00:1f.3: Turning i915 HDAC power 0
[   23.275989] sof-audio-pci-intel-cnl 0000:00:1f.3: Current DSP power state: D0I0
[   23.277380] sof-audio-pci-intel-cnl 0000:00:1f.3: loading firmware
[   23.278747] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIR: 00000002 at  00000048
[   23.280129] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIW: 00000000 at  00000048
[   23.281484] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIR: 00000000 at  00000044
[   23.282820] sof-audio-pci-intel-cnl 0000:00:1f.3: Debug PCIW: 00000004 at  00000044
[   23.284161] sof-audio-pci-intel-cnl 0000:00:1f.3: booting DSP firmware
[   23.285571] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0x40000 successful
[   23.286911] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0x40000 successful
[   23.288244] sof-audio-pci-intel-cnl 0000:00:1f.3: period_bytes:0x0
[   23.289620] sof-audio-pci-intel-cnl 0000:00:1f.3: periods:1
[   23.290957] sof-audio-pci-intel-cnl 0000:00:1f.3: Attempting iteration 0 of Core En/ROM load...
[   23.292236] sof-audio-pci-intel-cnl 0000:00:1f.3: DSP core(s) enabled? 0 : core_mask f
[   23.293554] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0xf0f0f0f successful
[   23.294898] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0xf0f0f00 successful
[   23.296197] sof-audio-pci-intel-cnl 0000:00:1f.3: unstall/run core: core_mask = f
[   23.297532] sof-audio-pci-intel-cnl 0000:00:1f.3: DSP core(s) enabled? 1 : core_mask f
[   23.298932] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0xf0f0000 successful
[   23.300238] sof-audio-pci-intel-cnl 0000:00:1f.3: unstall/run core: core_mask = 1
[   23.301572] sof-audio-pci-intel-cnl 0000:00:1f.3: DSP core(s) enabled? 1 : core_mask 1
[   23.803068] sof-audio-pci-intel-cnl 0000:00:1f.3: FW Poll Status: reg=0x0 timedout
[   23.804428] sof-audio-pci-intel-cnl 0000:00:1f.3: unknown ROM status value 05000001
[   23.805823] sof-audio-pci-intel-cnl 0000:00:1f.3: status = 0x00000000 panic = 0x00000000
[   23.807164] sof-audio-pci-intel-cnl 0000:00:1f.3: extended rom status:  0x5000001 0x0 0x0 0x0 0x0 0x0 0x1811102 0x0

@plbossart How did you save such message to the disk? I tried to save such message before but failed.

@plbossart

plbossart commented Mar 16, 2021 •

Copy link
Copy Markdown
Member Author

@plbossart How did you save such message to the disk? I tried to save such message before but failed.

I used netconsole on UpExtreme, it's got two Ethernet ports. see instructions here:
netconsole.txt

it's almost like a UART but over Ethernet (UDP packets).

The difficulty is finding a device with an Ethernet port, I don't think this works too well with USB dongles.

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, somewhat with uneasy. The probe_complete error paths have been problematic enough in the past, so not sure how we keep the error unroll paths in shutdown working. It would seem a brute-force shutdown that makes no assumtpions that driver+fw did sane things before sutdown, would be more sure and this is a code ptah we test every time we reboot a machine.

Comment thread sound/soc/sof/core.c Outdated
cancel_work_sync(&sdev->probe_work);

dev_dbg(dev, "%s: fw state %d\n", __func__, sdev->fw_state);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is useful. User-space is shutdown, so this log won't be seen in any normal log (i.e. no syslog/systemd anymore). You'll need a serial/netconsole to catch these, and then you probably can add additional traces as well.

Comment thread sound/soc/sof/core.c Resolved
Comment thread sound/soc/sof/pm.c Outdated
/* all update state to match */
sdev->fw_state = SOF_FW_BOOT_NOT_STARTED;

return ret;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very hard code to test for regressions, so I wonder if this is practical to add this. I mean if previously functioning device fails to boot after resume, something pretty bad has gone through.

I think it would be safer to have a more robust shutdown logic that would just shutdown the.

@plbossart

Copy link
Copy Markdown
Member Author

@ranj063 @kv2019i @libinyang see new log below. What's interesting is that something (PulseAudio?) opens a PCM device after the reboot command is issued, and the PCI device does a pm_runtime suspend while the reboot sequence is happening.

upextreme-reboot-loop5.txt

@plbossart

Copy link
Copy Markdown
Member Author

branch updated in case someone wants to give it a try with the same setup

@plbossart
plbossart marked this pull request as draft March 16, 2021 18:28
@plbossart plbossart changed the title ASoC: SOF: core: harden shutdown helper [TEST] ASoC: SOF: core: harden shutdown helper Mar 16, 2021
@plbossart

Copy link
Copy Markdown
Member Author

@ranj063 @kv2019i @libinyang now I have a sequence that is 100% reproducible.

When removing PulseAudio, there is no longer a pm_runtime_resume and pcm_open(), so the device has to be resumed in the shutdown sequence and that fails ALL THE TIME.

So it's really going back to D0 in the shutdown sequence that's problematic. If the device is in D0 the shutdown works fine.

upextreme-reboot-loop6.txt

I now suspect something in the PCI core that's doing things that get in the way of resuming?

@kv2019i

kv2019i commented Mar 17, 2021

Copy link
Copy Markdown
Collaborator

@plbossart wrote:

So it's really going back to D0 in the shutdown sequence that's problematic. If the device is in D0 the shutdown works fine.

upextreme-reboot-loop6.txt

I now suspect something in the PCI core that's doing things that get in the way of resuming?

Hmm, that could happen. I wonder if we could detect that we are shutting down somehow in the PM resume flow (and not really boot the DSP anymore). OTOH, this probably won't work as shutdown/reboot is not directly related to how kernel does suspend/resume.

This is still really strange why the boot fails. Some actions towards the DSP work. If some PCI level resources would have been taken down, I'd expect all I/O to fail. Maybe the fw-auth is not working anymore -- seems we don't complete the ROM execution successfully.

@libinyang

Copy link
Copy Markdown

@ranj063 @kv2019i @libinyang now I have a sequence that is 100% reproducible.

When removing PulseAudio, there is no longer a pm_runtime_resume and pcm_open(), so the device has to be resumed in the shutdown sequence and that fails ALL THE TIME.

So it's really going back to D0 in the shutdown sequence that's problematic. If the device is in D0 the shutdown works fine.

upextreme-reboot-loop6.txt

I now suspect something in the PCI core that's doing things that get in the way of resuming?

@plbossart I tried on my tgl board and I can't reproduce this issue with disabling or enabling the pulseaudio. And all our CI DUTs do the test with PA disabled. They will reboot after test, but we didn't find such issue on all DUTs. If this issue hangs at pm-runtime resume in shutdown, can we reproduce this issue in pure pm-runtime suspend/resume?

@libinyang

Copy link
Copy Markdown

This is still really strange why the boot fails. Some actions towards the DSP work. If some PCI level resources would have been taken down, I'd expect all I/O to fail. Maybe the fw-auth is not working anymore -- seems we don't complete the ROM execution successfully.

@kv2019i And it is strange that it shows "DSP core(s) enabled? 1 : core_mask f". I remember we only enable 1 core, do we?

@plbossart

Copy link
Copy Markdown
Member Author

@ranj063 @kv2019i @libinyang now I have a sequence that is 100% reproducible.
When removing PulseAudio, there is no longer a pm_runtime_resume and pcm_open(), so the device has to be resumed in the shutdown sequence and that fails ALL THE TIME.
So it's really going back to D0 in the shutdown sequence that's problematic. If the device is in D0 the shutdown works fine.
upextreme-reboot-loop6.txt
I now suspect something in the PCI core that's doing things that get in the way of resuming?

@plbossart I tried on my tgl board and I can't reproduce this issue with disabling or enabling the pulseaudio. And all our CI DUTs do the test with PA disabled. They will reboot after test, but we didn't find such issue on all DUTs. If this issue hangs at pm-runtime resume in shutdown, can we reproduce this issue in pure pm-runtime suspend/resume?

You can only see the issue if you have netconsole or a UART link. If you don't then you would never know there was a problem.

@libinyang

libinyang commented Mar 19, 2021 •

Copy link
Copy Markdown

You can only see the issue if you have netconsole or a UART link. If you don't then you would never know there was a problem.

@plbossart I captured the dmesg with a camera. It shows OK on my TGL platform. Please see the attachment. (I have disabled PA)
112317145

@plbossart

Copy link
Copy Markdown
Member Author

You can only see the issue if you have netconsole or a UART link. If you don't then you would never know there was a problem.

@plbossart I captured the dmesg with a camera. It shows OK on my TGL platform. Please see the attachment. (I have disabled PA)
112317145

Ack, that's useful. thanks @libinyang. I think we have possible BIOS issues here.

@plbossart plbossart changed the title [TEST] ASoC: SOF: core: harden shutdown helper ASoC: SOF: core: harden shutdown helper Mar 19, 2021
@plbossart
plbossart marked this pull request as ready for review March 19, 2021 18:16
When the probe is handled in a workqueue, we must use
cancel_work_sync() in the shutdown helper to avoid possible race
conditions.

We must also take care of possible errors happening in a probe
workqueue or during pm_runtime resume (called e.g. before shutdown for
PCI devices). We should really only try to access hardware registers
and initiate IPCs if the DSP is fully booted.

Fixes: daff7f1 ("ASoC: SOF: add snd_sof_device_shutdown() helper for shutdown")
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
@plbossart

Copy link
Copy Markdown
Member Author

@libinyang @kv2019i @ranj063 I went back to a minimal fix, we'll have to deal with the firmware authentication during pm_runtime_resume as a separate, possibly device-specific, issue.

@libinyang libinyang left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kv2019i
kv2019i merged commit b052d49 into thesofproject:topic/sof-dev Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants